package com.taysear.parcel;

import com.taysear.parcel.domain.Loadingsheet;
import com.taysear.parcel.domain.Parcel;
import com.vaadin.terminal.StreamResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class PrintToPDF extends Window {
	
	ParcelApplication app;
	
	public PrintToPDF(ParcelApplication app) {
		
	}
	
	public PrintToPDF(ParcelApplication app, Parcel parcel) {
    	this.app = app;
    	
        ((VerticalLayout) getContent()).setSizeFull();
        setResizable(true);
        setCaption("Print parcel");
        setWidth("800");
        setHeight("600");
        center();
        setModal(true);
        
        Embedded e = new Embedded();
        e.setSizeFull();
        e.setType(Embedded.TYPE_BROWSER);

        // Here we create a new StreamResource which downloads our StreamSource, which is our pdf.
        StreamResource resource = new StreamResource(new Pdf(app, parcel), "parcel_print_out_" + System.currentTimeMillis() + ".pdf", app);
        // Set the right mime type
        resource.setMIMEType("application/pdf");

        e.setSource(resource);
        
        Button close = new Button("Close", new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
            	
            }
        });
        close.addStyleName("grayButton");
        //addComponent(close);
        addComponent(e);
    }
	
    public PrintToPDF(ParcelApplication app, Loadingsheet loadingsheet) {
    	this.app = app;
    	
        ((VerticalLayout) getContent()).setSizeFull();
        setResizable(true);
        setCaption("Print loadingsheet");
        setWidth("800");
        setHeight("600");
        center();
        setModal(true);
        
        Embedded e = new Embedded();
        e.setSizeFull();
        e.setType(Embedded.TYPE_BROWSER);

        // Here we create a new StreamResource which downloads our StreamSource, which is our pdf.
        StreamResource resource = new StreamResource(new Pdf(app, loadingsheet), "loadingsheet_print_out_" + System.currentTimeMillis() + ".pdf", app);
        // Set the right mime type
        resource.setMIMEType("application/pdf");

        e.setSource(resource);
        
        Button close = new Button("Close", new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
            	
            }
        });
        //addComponent(close);
        addComponent(e);
    }
}